<template>
    <div class="details">
        <navs :navtitle="title"></navs>
        <div class="wrap">
            <div class="img-wrap">
                <van-swipe indicator-color="red">
                    <van-swipe-item @click="imagePreview(urlImg)" v-for="(item,index) in urlImg" :key="index"><img class="imgs" :src="item" alt=""></van-swipe-item>
                </van-swipe>
            </div>
            <div class="content">
                <span class="content-top">{{result.goodsName}}</span>
                <div class="content-mon">
                    <p class="mon-left">￥<span class="money">{{result.orderPrice|addZero}}</span></p>
                    <p class="mon-right">1提起批</p>
                </div>
                <div class="content-bottom">
                    <span>库存{{results.skuSaleNum}}{{result.measurementUnit}}</span>
                    <span>月销{{results.salesNum}}{{result.measurementUnit}}</span>
                    <span>{{result.integerZeroConvert}}</span>
                </div>
            </div>
            
            <shoppingCar :goodsId="this.$route.query.skuid">
                <div class="selected">
                    <div class="selecteds">
                        <div class="selecteds-left">
                            <span class="xuan">已选</span>
                            <span class="danwei">12盒</span>
                        </div>
                        <i class="iconfont icon-right"></i>
                    </div>
                </div>
            </shoppingCar>
            <div class = "tabs">
                <van-tabs swipeable sticky>
                    <van-tab title="商品介绍">
                        <p v-html = "results.description" ref = "tabUrlImg"></p>
                    </van-tab>
                    <van-tab title="规格参数">
                        <p v-html = "paramsImg"></p>
                    </van-tab>
                </van-tabs>
            </div>
            <div class="bottom">
                <ul class="bottom-left">
                    <router-link tag="li" to="/shop">
                        <i class="iconfont icon-jinrudianpu"></i>
                        <p>店铺</p>
                    </router-link>
                    <li>
                        <i class="iconfont icon-shoucang"></i>
                        <p>收藏</p>
                    </li>
                    <router-link tag="li" to="/shopping">
                        <i class="iconfont icon-gou_wu_che2"></i>
                        <p>购物车</p>
                        <p v-if="goods" class="counts">{{goods}}</p>
                    </router-link>
                </ul>
                <shoppingCar :goodsId="this.$route.query.skuid" v-if="results.skuSaleNum">
                    <div class="bottom-right" @click="shoppingCar">加入购物车</div>
                </shoppingCar>
                <div v-else class="bottom-buhuo">补货中</div>
                
            </div>
            <!-- <div class="bottom" >
                <ul class="bottom-left">
                    <li>
                        <i class="iconfont icon-jinrudianpu"></i>
                        <p>店铺</p>
                    </li>
                    <li>
                        <i class="iconfont icon-shoucang"></i>
                        <p>收藏</p>
                    </li>
                    <li>
                        <i class="iconfont icon-gou_wu_che2"></i>
                        <p>购物车</p>
                    </li>
                </ul>
                
            </div> -->
            <Navigation></Navigation>
        </div>
    </div>
</template>
<script>
import navs from "../components/Navbar"
import { Tab, Tabs } from 'vant';
import Vue from 'vue';
import { parse } from 'path';
Vue.use(Tab).use(Tabs);
import { Swipe, SwipeItem } from 'vant';
Vue.use(Swipe).use(SwipeItem);
import { ImagePreview } from 'vant';
Vue.use(ImagePreview);
import Navigation from '../components/Navigation'
import shoppingCar from '../components/shoppingCar'
export default {
    components:{
        navs,
        Navigation,
        shoppingCar
    },
    data(){
        return{
            title:'商品详情',
            result:[],
            results:[],
            skuid:'',
            urlImg: [],
            paramsImg: "",
            car:false,
            activeBoo:false,
            
        }
    },
    created(){
        console.log("vuex",this.$store.state.storhuaallnameall)
        //result
    },
    methods:{
        //图片预览
        imagePreview(data){
            ImagePreview({
                images:[...data]
            }
            );

        },
        con(){
            if(this.result.ratio1>=this.results.skuSaleNum){
                console.log('库存不足')
            }else{
                this.result.ratio1+=1
            }
            
        },
        cons(){
            if(this.result.ratio1!=0){
                this.result.ratio1-=1
            }         
        },
        getcollecteds(){
            let headers;
            if (this.$store.state.token) {
                headers = {
                token: this.$store.state.token,
                userId: this.$store.state.userInfo.id
                };
            } else {
                headers = {};
            }
            let skuids=this.skuid
            let stationId=this.$store.state.stationId
            let userId=this.$store.state.userInfo.id
            let shopId=this.$store.state.storeId.storeId
            let merchantId=this.$store.state.merchantInfo.merchantId
            let storeId=this.$store.state.storeId.id
            console.log( skuids,stationId,userId,shopId,merchantId,storeId)
            this.$http.get("https://web-gateway.newbeescm.com/b2b-app-web/goodsDetail/"+skuids+'/'+stationId+'/'+userId+'/'+shopId+'/'+merchantId+'/'+storeId,
                {
                    headers,
                })
                .then(res => {
                console.log(res)
                if(res.data.status.statusCode===0){
                    console.log("数据")
                    if(res.data.result.goodsOl){
                         this.result = res.data.result.goodsOl;
                         this.results = res.data.result;
                         this.urlImg = res.data.result.goodsOl.picsUrl.split(",")
                        //  this.$store.commit('setDealerIds',res.data.result.goodsOl);
                    }          
                }                
                })
                .catch(err => {
                    console.log(err);
                });
        },
        getGoodsParamsBySkuId(){
                  let headers;
            if (this.$store.state.token) {
                headers = {
                token: this.$store.state.token,
                userId: this.$store.state.userInfo.id
                };
            } else {
                headers = {};
            }
            let skuids=this.skuid
            let storeGlobalId=this.$store.state.storeId.storeId
            let storeGroupId=this.$store.state.storeId.id
            this.$http.get("https://web-gateway.newbeescm.com/b2b-app-web/html/getGoodsParamsBySkuId/"+skuids,
                {
                    headers,
                    params:{
                        storeGlobalId:storeGlobalId,
                        storeGroupId:storeGroupId
                    },
                    
                })
                .then(res => {
                console.log(res);
                if(res.data) {
                    this.paramsImg = res.data
                }                
                })
                .catch(err => {
                    console.log(err);
                });
        },
        shoppingCar(){
            this.car = !this.car
        },
        select(){
            this.activeBoo=!this.activeBoo
        },
    },
    mounted(){
        //this.$route.query.indexscorrl
        this.skuid=this.$route.query.skuid
        this.getcollecteds();
        this.getGoodsParamsBySkuId();
    },
    computed:{
        Price(){
            return this.result.orderPrice*this.result.ratio1
        },
        goods(){
            return this.$store.state.good.goodsCount
        }
        
    },
    filters:{
        addZero(value){
            if(isNaN(Number(value))){
                return value
            }
            return Number(value).toFixed(2)
        }
    }
}
</script>
<style scoped lang="scss">
@import "../untils/tab.css";
.wrap{
    padding-bottom: 0.49rem;
}
.img-wrap{
    height: 3.75rem;
    position: relative;
    img{
        width: 100%;
        height: 100%;
        background: pink;
        display: block;
    }
}
.img-wrap::after{
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: #F2F1F6;
    transform: scale(1,0.5);
}
.content{
    padding: 0.15rem;
    .content-top{
        font-size: 0.14rem;
        color: #333;
        font-weight: 600;
    }
    .content-mon{
        margin: 0.15rem 0;
        display: flex;
        .mon-left{
            color: #dd3333;
            font-size: 0.14rem;
            .money{
                font-size: 0.18rem;
            }
        }
        .mon-right{
            font-size: 0.12rem;
            color: #666;
            margin-left: 0.3rem;
        }
    }
    .content-bottom{
        line-height: 0.12rem;
        span{
            font-size: 0.12rem;
            color: #999;
            margin-right: 0.1rem;
            
        }
    }
}
.selected{
    background: #F2F1F6;
    padding: 0.1rem 0;
    .selecteds{
        padding: 0.165rem 0.14rem;
        background: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
        .selecteds-left{
            line-height: 0.14rem;
            .xuan{
                font-size: 0.14rem;
                color: #666;
                margin-right: 0.4rem;
            }
            .danwei{
                font-size: 0.14rem;
                color: #333;
            }
        }
        .icon-right{
            font-size: 0.16rem;
            color: #999;
        }
    }
}
.list-can{
    li{
        padding:0.14rem;
        display: flex;
        border-bottom: 1px solid #F2F1F6;
        .ch{
            width: 1rem;
            font-size: 0.14rem;
            color: #939393;
        }
        .dizhi{
            font-size: 0.14rem;
            color: #333;
        }
    }
}
.bottom{
    height: 0.49rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255,255,255,0.90);
    box-shadow: inset 0 0 0 0 #E1E1E1;
    z-index: 99;
    .bottom-left{
        display: flex;
        flex: 1;
        justify-content: space-around;
        li{
            text-align: center;
            .icon-jinrudianpu,.icon-shoucang,.icon-gou_wu_che2{
                font-size: 0.18rem;
                color: #666;
            }
            p{
                font-size: 0.11rem;
                color: #666;
            }
        }
    }
    .bottom-right{
        width: 1.2rem;
        height: 0.49rem;
        color: #fff;
        line-height: 0.49rem;
        text-align: center;
        background: #dd3333;
    }
    .counts{
                width: 0.12rem;
                height: 0.12rem;
                background: #DD3333;
                color: #fff !important;
                border-radius: 50%;
                text-align: center;
                line-height: 0.12rem;
                position: absolute;
                left: 58%;
                top: 0.05rem;
                font-size: 0.09rem;
            }
    .bottom-buhuo{
        width: 1.2rem;
        height: 0.49rem;
        color: #fff;
        line-height: 0.49rem;
        text-align: center;
        background: #ccc;
    }
}
.shoppingShow{
    position: fixed;
    top: 0.43rem;
    left: 0;
    right: 0;
    z-index: 1000;
    bottom: 0.49rem;
    display: grid;
    grid-template-rows: 1rem 1fr;
    .shoppingShow-header{
        background: #000;
        opacity: 0.5;
    }
    .shoppingShow-content{
        background: #fff;
        .shoppingShow-content-top{
            padding: 0.14rem;
            display: flex;
            justify-content: space-between;
            img{
                width: 1.06rem;
                height: 1.06rem;
            }
            .shoppingShow-content-top-title{
                p{
                    font-size: 0.14rem;
                    margin-top: 0.1rem;
                    margin-bottom: 0.12rem;
                }
                .shopping-money{
                    font-size: 0.12rem;
                    color: #dd3333;
                    .spn{
                        font-size: 0.2rem;
                        margin-left: 0.05rem;
                    }
                    .spns{
                        color: #666;
                        margin-left: 0.1rem;
                    }
                }
            }
            .quxiao{
                width: 0.12rem;
                height: 0.12rem;
            }
        }
        .shoppingShow-content-dan{
            padding-left: 0.14rem;
            padding-bottom: 0.1rem;
            position: relative;
            span{
                font-size: 0.12rem;
                color: #999;
                margin-right: 0.2rem;
            }
        }
        .shoppingShow-content-dan::after{
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 1px;
            background: #E1E1E1;
            transform: scale(1,0.5);
        }
        .shoppingShow-content-count{
            padding: 0.1rem 0.14rem;
            display: flex;
            justify-content: space-between;
            p{
                font-size: 0.14rem;
                color: #999;
            }
            .shoppingShow-content-count-right{
                display: flex;
                p{
                    width: 0.28rem;
                    height: 0.28rem;
                    text-align: center;
                    line-height: 0.25rem;
                    border: 1px solid #9b9b9b;
                    color: #333;
                    font-size: 0.12rem;
                    border-radius: 0.03rem;
                    box-sizing: border-box;
                    margin-right: 0.1rem;
                }
                .active{
                    color: #fff;
                    background: #dd3333;
                }
                button{
                    width: 0.28rem;
                    height: 0.28rem;
                    text-align: center;
                    line-height: 0.25rem;
                    // color: #fff;
                }
                input{
                    width: 0.51rem;
                    height: 0.26rem;
                    border: none;
                    border-top: 1px solid #9b9b9b;
                    border-bottom: 1px solid #9b9b9b;
                    text-align: center;
                }
            }
        }
    }
}
.bottoms{
    justify-content: flex-end;
    .bottom-money{
        span{
            color: #dd3333;
            padding-left: 0.1rem;
            padding-right: 0.2rem;
        }
    }
    .bottom-buhuo{
        width: 1.2rem;
        height: 0.49rem;
        color: #fff;
        line-height: 0.49rem;
        text-align: center;
        background: #ccc;
    }
}
</style>
